//
//  OASectionConfig.h
//  OASDK_Works
//
//  Created by ChenJie on 3/29/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "OACellConfig.h"

@class OATableConfig;

@interface OASectionConfig : NSObject

@property (nonatomic, copy) NSString *name;

/* section */
@property (nonatomic, copy) NSString *headerTitle;
@property (nonatomic, copy) NSString *footerTitle;
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, assign) CGFloat footerHeight;

/* section index */
@property (nonatomic, assign, readonly) NSInteger sectionIndex;
@property (nonatomic, copy) NSInteger (^indexOfSection)(OASectionConfig *sectionConfig);

/* table */
@property (nonatomic, strong, readonly) OATableConfig *tableConfig;
@property (nonatomic, copy) OATableConfig * (^tableOfSection)(void);

/* init */
+ (instancetype)sectionWithName:(NSString *)name;
+ (instancetype)section;

/* add cell */
- (OACellConfig *)addCell:(OACellConfig *)cell;
- (OACellConfig *)addCellWithType:(NSString *)cellType viewModel:(id)viewModel;
- (OACellConfig *)addCellWithType:(NSString *)cellType staticHeight:(CGFloat)staticHeight viewModel:(id)viewModel;
- (OACellConfig *)addCellWithName:(NSString *)cellName type:(NSString *)cellType viewModel:(id)viewModel;

- (OACellConfig *)addCellWithName:(NSString *)cellName
                             type:(NSString *)cellType
                     staticHeight:(CGFloat)staticHeight
                        viewModel:(id)viewModel;

/* insert Cell */
- (OACellConfig *)insertCell:(OACellConfig *)cell atIndex:(NSInteger)cellIndex;
- (OACellConfig *)insertCell:(OACellConfig *)cell beforeCell:(OACellConfig *)referenceCell;
- (OACellConfig *)insertCell:(OACellConfig *)cell afterCell:(OACellConfig *)referenceCell;

/* delete cell */
- (void)deleteCell:(OACellConfig *)cell;
- (void)deleteCellAtIndex:(NSInteger)cellIndex;
- (void)deleteCellWithName:(NSString *)cellName;
- (void)deleteCellBeforeCell:(OACellConfig *)referenceCell;
- (void)deleteCellAfterCell:(OACellConfig *)referenceCell;

/* get cell */
- (OACellConfig *)cellAtIndex:(NSInteger)cellIndex;
- (OACellConfig *)cellWithName:(NSString *)cellName;

/* get cellViewModel */
- (id<OACellViewModelProtocol>)viewModelAtIndex:(NSInteger)cellIndex;
- (id<OACellViewModelProtocol>)viewModelWithName:(NSString *)cellName;

/* update cell */
- (void)updateCell:(OACellConfig *)cell;
- (void)updateCell:(OACellConfig *)cell withAnimation:(UITableViewRowAnimation)animation;

/* update section */
- (void)updateSection;
- (void)updateSectionWithAnimation:(UITableViewRowAnimation)animation;

#pragma mark - Delegate methods

/* UITableViewDataSource */
- (NSInteger)numberOfRowsInSection;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex:(NSInteger)cellIndex;

/* UITableViewDelegate */
- (CGFloat)heightForRowWithCellWidth:(CGFloat)cellWidth cellIndex:(NSInteger)cellIndex;
- (void)didSelectRowAtIndex:(NSInteger)cellIndex;

@end

